'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  //登录
  router.post('/api/login', controller.user.login);
  //注册
  router.post("/api/lll", async function (ctx) {
    const {
      username,
      password, identity
    } = ctx.request.body;
    const md5 = require("md5")
    console.log(md5(password));
    await this.app.mysql.insert('user', {
      username,
      password: md5(password), identity
    })
    ctx.body = "注册成功"
  })
  //获取房子数据
  router.post("/api/getRoomList", controller.room.getList);
  //删除房屋数据
  router.delete("/api/delRoom", controller.room.del);
  //添加房屋数据
  router.post("/api/addRoom", controller.room.add);
  //编辑房屋数据
  router.put("/api/editRoom", controller.room.edit);

  //获取经纪人数据
  router.get("/api/getUser", controller.user.getList);

  //团购信息
  router.post("/api/getGroupList", controller.group.getList);
  //删除t团购数据
  router.delete("/api/delGroup", controller.group.del);
  //编辑房屋数据
  router.put("/api/editGroupState", controller.group.edit);


  //审核管理
  router.post("/api/getToExamineList", controller.toExamine.getList);
  //删除审核
  router.delete("/api/delToExamine", controller.toExamine.del);
  //编辑房屋数据
  router.put("/api/editToExamine", controller.toExamine.edit);

  //订单管理
  router.post("/api/getOrderList", controller.order.getList);
  //删除审核
  router.delete("/api/delOrder", controller.order.del);

  //咨询管理
  router.post("/api/getInfosList", controller.infos.getList);
  //删除
  router.delete("/api/delInfos", controller.infos.del);
  //编辑
  router.put("/api/editInfos", controller.infos.edit);

  //经纪人管理
  router.post("/api/getAgentList", controller.agent.getList);
  //新增
  router.post("/api/addAgent", controller.agent.add);
  //编辑
  router.put("/api/editAgent", controller.agent.edit);
  //删除
  router.delete("/api/delAgent", controller.agent.del);


  //*****************经纪人段端******************** */
  //获取验证码
  router.post("/api/getVerification", controller.agentUser.getVerification);
  //登录
  router.post("/api/agentLogin", controller.agentUser.login);


  //楼市圈
  router.get("/api/getShareList", controller.share.getList);
  //上传图片
  router.post("/api/shareUpload", controller.share.upload);
  //添加楼市圈
  router.post("/api/addShare", controller.share.addShare);

  //获取消息列表
  router.get("/api/getNews", controller.news.getList);
  //获取好友列表
  router.get("/api/goodFriend", controller.news.getGoodList)
  //发送消息
  router.post("/api/sendNews", controller.news.send);
  //删除公告
  router.delete("/api/notice", controller.news.delNotice);
  //清空新消息
  router.put("/api/clearQuantity", async (ctx) => {
    const { id } = ctx.request.body;
    await ctx.app.mysql.update("goodFriend", { id, quantity: 0 });
    ctx.body = "ok";
  })


  // 新房
  //获取房源数据
  router.get('/api/houseAgent', controller.houseAgent.index);
  //获取求租数据
  router.get('/api/purAgent', controller.purAgent.index);
  //团购
  //获取团购数据
  router.get('/api/groupAgent', controller.groupAgent.index);
  //删除团购数据
  router.delete('/api/groupAgent', controller.groupAgent.delGroup);
  //获取团购详情数据
  router.get('/api/groupDetail', controller.groupAgent.detailGroup);
  //获取团购数据
  router.post('/api/groupAgent', controller.groupAgent.setGroup);
  //创建团购
  router.put('/api/groupAgent', controller.groupAgent.addGroup);

};
